﻿#region License
/* Copyright (C) 2009 Marcus Lindblom
 * 
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
#endregion
using System.Web;
using System.Web.Script.Serialization;

namespace Meridium.EPCms.Lixr.Meridium.Lixr.Web.Handlers {
    /// <summary>
    /// 
    /// </summary>
    public class Lixr : IHttpHandler {
        /* *******************************************************************
         * Properties
         * *******************************************************************/
        #region public bool IsReusable
        /// <summary>
        /// Gets the IsReusable of the Lixr
        /// </summary>
        /// <value></value>
        public bool IsReusable {
            get {
                return true;
            }
        }
        #endregion
        /* *******************************************************************
         * Methods
         * *******************************************************************/
        #region public void ProcessRequest(HttpContext context)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context) {
            context.Response.ContentType = "application/json";

            string text = context.Request.Form["text"];
            if(string.IsNullOrEmpty(text))
                return;

            EPCms.Lixr.Lixr lixr = new EPCms.Lixr.Lixr(text);
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(lixr);
            context.Response.Write(json);
        }
        #endregion
    }
}